/**
 * Validiert die Einlass-Uhrzeit.
 * 
 * @author Michael Serajnik, Manuel Leitner
 */

package at.fhj.itm10.ticketmaster.validators;

import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.validator.FacesValidator;
import javax.faces.validator.Validator;
import javax.faces.validator.ValidatorException;

@FacesValidator(value = "EventEntryValidator")
public class EventEntryValidator implements Validator {

	public void validate(FacesContext context, UIComponent component, Object value)
			throws ValidatorException {
		
		String eventEntry = (String) value;
		String regEx = "^([0-1][0-9]|[2][0-3]):([0-5][0-9])$";
		
		if(eventEntry == null || eventEntry.matches(regEx) == false) {
			throw new ValidatorException(new FacesMessage("Bitte gib eine g\u00FCltige Einlass-Uhrzeit im Format \"HH:MM\" an."));
		}
		
	}

}
